#!/usr/bin/env ruby
require 'rubygems'
require 'daemons/rails/config'


num = ENV['PUSHER'] ? ENV['PUSHER'].to_i : 1

num.times do |i|
  if pid = fork
    Process.detach pid
  else
    config = Daemons::Rails::Config.for_controller(File.expand_path(__FILE__))

    config[:app_name] = "peatio:amqp:pusher:#{i+1}"
    config[:script]   = "#{File.expand_path('../amqp_daemon.rb', __FILE__)}"
    config[:ARGV]     = ARGV + %w(-- pusher_market pusher_member)

    Daemons::Rails.run config[:script], config.to_hash

    break
  end
end
